package com.xl.adminserver.beans;

import lombok.Builder;
import lombok.Data;

/**
 * @author 唐植超
 * @date 2019/11/18
 */
@Data
@Builder
public class RestApiResult<T> {

    private int code;
    private String errmsg;
    private T data;

    public RestApiResult(T data) {
        this.data = data;
        this.code = 0;
        this.errmsg = "操作成功";
    }

    public RestApiResult(int code, String errmsg) {
        this.code = code;
        this.errmsg = errmsg;
    }

    public RestApiResult(int code, String errmsg, T data) {
        this.code = code;
        this.errmsg = errmsg;
        this.data = data;
    }

    public static RestApiResult error(String errmsg) {
        return new RestApiResult(500, errmsg);
    }

    public static RestApiResult ok(Object data) {
        return new RestApiResult(0, "success", data);
    }
}
